<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RocketMQ 分布式消息系统深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        /* Hero Section */
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        /* 卡片悬停效果 */
        .card-hover {
            transition: all 0.3s ease;
            border: 1px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            border-color: #667eea;
        }
        
        /* 标题装饰 */
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            bottom: -10px;
            width: 60px;
            height: 4px;
            background: linear-gradient(90deg, #667eea, #764ba2);
            border-radius: 2px;
        }
        
        /* 代码块样式 */
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            padding: 1.5rem;
            overflow-x: auto;
            font-family: 'Consolas', 'Monaco', monospace;
            position: relative;
        }
        
        .code-block::before {
            content: attr(data-lang);
            position: absolute;
            top: 0.5rem;
            right: 1rem;
            color: #666;
            font-size: 0.75rem;
            text-transform: uppercase;
        }
        
        /* 首字下沉 */
        .drop-cap::first-letter {
            float: left;
            font-size: 4rem;
            line-height: 3rem;
            padding-right: 0.5rem;
            font-weight: 700;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        /* 引用样式 */
        .quote-box {
            border-left: 4px solid #667eea;
            padding-left: 1.5rem;
            margin: 2rem 0;
            font-style: italic;
            color: #4a5568;
            background: rgba(102, 126, 234, 0.05);
            padding: 1.5rem;
            border-radius: 0 8px 8px 0;
        }
        
        /* 数字指标卡片 */
        .metric-card {
            background: white;
            border-radius: 12px;
            padding: 1.5rem;
            text-align: center;
            transition: all 0.3s ease;
        }
        
        .metric-card:hover {
            transform: scale(1.05);
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }
        
        .metric-number {
            font-size: 2.5rem;
            font-weight: 700;
            background: linear-gradient(135deg, #667eea, #764ba2);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        
        /* 时间线样式 */
        .timeline-item {
            position: relative;
            padding-left: 3rem;
            margin-bottom: 2rem;
        }
        
        .timeline-item::before {
            content: '';
            position: absolute;
            left: 0;
            top: 0;
            width: 1rem;
            height: 1rem;
            background: #667eea;
            border-radius: 50%;
            box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.2);
        }
        
        .timeline-item::after {
            content: '';
            position: absolute;
            left: 0.5rem;
            top: 1rem;
            width: 1px;
            height: calc(100% + 1rem);
            background: #e2e8f0;
        }
        
        .timeline-item:last-child::after {
            display: none;
        }
        
        /* 滚动动画 */
        .fade-in {
            opacity: 0;
            transform: translateY(20px);
            transition: all 0.6s ease;
        }
        
        .fade-in.visible {
            opacity: 1;
            transform: translateY(0);
        }
        
        /* Mermaid 图表样式 */
        .mermaid {
            background: white;
            padding: 2rem;
            border-radius: 12px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 animate-pulse">
                    RocketMQ 分布式消息系统
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">
                    深度解析企业级消息中间件的核心技术与最佳实践
                </p>
                <div class="flex justify-center space-x-6">
                    <div class="metric-card bg-white bg-opacity-20 backdrop-blur">
                        <div class="metric-number text-white">99.99%</div>
                        <p class="text-sm mt-2">可用性保证</p>
                    </div>
                    <div class="metric-card bg-white bg-opacity-20 backdrop-blur">
                        <div class="metric-number text-white">10万+</div>
                        <p class="text-sm mt-2">TPS处理能力</p>
                    </div>
                    <div class="metric-card bg-white bg-opacity-20 backdrop-blur">
                        <div class="metric-number text-white">&lt;1ms</div>
                        <p class="text-sm mt-2">消息延迟</p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Navigation -->
    <nav class="sticky top-0 bg-white shadow-md z-50">
        <div class="container mx-auto px-6 py-4">
            <div class="flex justify-center space-x-8">
                <a href="#consistency" class="text-gray-700 hover:text-purple-600 transition">
                    <i class="fas fa-shield-alt mr-2"></i>一致性保证
                </a>
                <a href="#monitoring" class="text-gray-700 hover:text-purple-600 transition">
                    <i class="fas fa-chart-line mr-2"></i>监控运维
                </a>
                <a href="#deployment" class="text-gray-700 hover:text-purple-600 transition">
                    <i class="fas fa-globe mr-2"></i>跨区域部署
                </a>
            </div>
        </div>
    </nav>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12">
        
        <!-- Section 1: 消息一致性保证机制 -->
        <section id="consistency" class="mb-20 fade-in">
            <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12">
                <h2 class="text-4xl font-bold mb-8 relative section-title">
                    <i class="fas fa-shield-alt text-purple-600 mr-3"></i>
                    消息一致性保证机制
                </h2>
                
                <!-- 一致性模型与挑战 -->
                <div class="mb-12">
                    <h3 class="text-2xl font-semibold mb-6 text-gray-800">
                        <i class="fas fa-puzzle-piece text-purple-500 mr-2"></i>
                        一致性模型与挑战
                    </h3>
                    <p class="text-lg text-gray-700 mb-6 drop-cap">
                        在分布式消息系统中，消息一致性是指确保消息在生产者、Broker和消费者之间传递过程中不丢失、不重复、按序到达的能力。RocketMQ面临的一致性挑战主要包括：
                    </p>
                    
                    <div class="grid md:grid-cols-2 gap-6 mb-8">
                        <div class="card-hover bg-gradient-to-br from-purple-50 to-pink-50 p-6 rounded-xl">
                            <h4 class="font-semibold text-lg mb-3 text-purple-700">
                                <i class="fas fa-network-wired mr-2"></i>分布式环境的不确定性
                            </h4>
                            <p class="text-gray-600">网络分区、节点故障、时钟偏移等问题带来的挑战</p>
                        </div>
                        <div class="card-hover bg-gradient-to-br from-blue-50 to-cyan-50 p-6 rounded-xl">
                            <h4 class="font-semibold text-lg mb-3 text-blue-700">
                                <i class="fas fa-balance-scale mr-2"></i>性能与一致性的权衡
                            </h4>
                            <p class="text-gray-600">强一致性通常意味着更高的延迟和更低的吞吐量</p>
                        </div>
                        <div class="card-hover bg-gradient-to-br from-green-50 to-emerald-50 p-6 rounded-xl">
                            <h4 class="font-semibold text-lg mb-3 text-green-700">
                                <i class="fas fa-sync-alt mr-2"></i>多副本数据同步
                            </h4>
                            <p class="text-gray-600">主从节点间数据同步的实时性与可靠性</p>
                        </div>
                        <div class="card-hover bg-gradient-to-br from-orange-50 to-yellow-50 p-6 rounded-xl">
                            <h4 class="font-semibold text-lg mb-3 text-orange-700">
                                <i class="fas fa-tasks mr-2"></i>消费进度管理
                            </h4>
                            <p class="text-gray-600">在消费者故障或重启后如何准确恢复消费位点</p>
                        </div>
                    </div>
                </div>

                <!-- 存储一致性保证 -->
                <div class="mb-12">
                    <h3 class="text-2xl font-semibold mb-6 text-gray-800">
                        <i class="fas fa-database text-purple-500 mr-2"></i>
                        存储一致性保证
                    </h3>
                    
                    <!-- 刷盘策略 -->
                    <div class="mb-8">
                        <h4 class="text-xl font-semibold mb-4 text-gray-700">刷盘策略</h4>
                        <div class="grid md:grid-cols-2 gap-6">
                            <div class="bg-gray-50 p-6 rounded-lg">
                                <h5 class="font-semibold text-lg mb-3 text-purple-600">
                                    <i class="fas fa-lock mr-2"></i>同步刷盘
                                </h5>
                                <p class="text-gray-600 mb-3">消息写入内存后，立即将数据刷写到磁盘，只有在刷盘成功后才向生产者返回成功响应</p>
                                <div class="flex items-center space-x-4 text-sm">
                                    <span class="text-green-600"><i class="fas fa-check-circle mr-1"></i>消息不会因Broker宕机而丢失</span>
                                    <span class="text-red-600"><i class="fas fa-times-circle mr-1"></i>TPS降低10%~30%</span>
                                </div>
                            </div>
                            <div class="bg-gray-50 p-6 rounded-lg">
                                <h5 class="font-semibold text-lg mb-3 text-blue-600">
                                    <i class="fas fa-bolt mr-2"></i>异步刷盘
                                </h5>
                                <p class="text-gray-600 mb-3">消息写入内存后立即返回成功，后台线程定期将数据刷写到磁盘</p>
                                <div class="flex items-center space-x-4 text-sm">
                                    <span class="text-green-600"><i class="fas fa-check-circle mr-1"></i>性能高，吞吐量大</span>
                                    <span class="text-red-600"><i class="fas fa-times-circle mr-1"></i>可能导致消息丢失</span>
                                </div>
                            </div>
                        </div>
                        
                        <div class="mt-6">
                            <div class="code-block" data-lang="java">
<pre>// org.apache.rocketmq.store.config.FlushDiskType
public enum FlushDiskType {
    // 同步刷盘
    SYNC_FLUSH,
    // 异步刷盘
    ASYNC_FLUSH
}</pre>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 投递一致性保证 -->
                <div class="